import {getAllArray, getArrayDetailById} from '@/api'
const state = {
    arrays:{},
    arrayDetail:{},
    filterOptions:{
        id:"0",
        pageSize: "2",
        pageIndex: "1",
        classify:"所有",
        form_of_sale:"所有",
        minprice:0,
        maxprice:1000000
    }
}

const mutations = {
    ARRAYS(context, data){
        context.arrays = data
    },
    ARRAYDETAIL(context, data){
        context.arrayDetail = data
    },
    FILTEROPTIONS(context, data){
        context.filterOptions = data
    }
}

const actions = {
    async arrays({commit}, params){
        let {pageIndex, pageSize} = params
        let result = await getAllArray(pageIndex, pageSize)
        commit("ARRAYS", result)
    },

    async arrayDetail({commit}, params){
        commit("FILTEROPTIONS", params)
        let result = await  getArrayDetailById(params)
        if(result.flag != false){
            commit("ARRAYDETAIL", result)
        }
    }
}

const getters = {}

export default {
    state,
    mutations,
    actions,
    getters
}